﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using ClassLibrary.DAO;
using ClassLibrary.Data;
using ClassLibrary.Entity;

public partial class Admin_ListLayout : AdminPage
{
    TblLayoutCodeDAO LayoutCodeDAO = new TblLayoutCodeDAO(Global.CONNECTION_STRING);
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            LoadListLayout();
        }
    }

    private void LoadListLayout()
    {
        grdListlayout.DataSource = LayoutCodeDAO.ListLayout();
        grdListlayout.DataBind();
    }
    protected void grdListlayout_RowDataBound(object sender, GridViewRowEventArgs e)
    {
        if (e.Row.RowType == DataControlRowType.DataRow)
        {
            foreach (DataControlFieldCell cell in e.Row.Cells)
            {
                // check all cells in one row
                foreach (Control control in cell.Controls)
                {
                    ImageButton button = control as ImageButton;
                    if (button != null && button.CommandName == "Delete")
                    {
                        // Add delete confirmation
                        //button.CommandArgument = ((TblEmail)e.Row.DataItem).IDEmail.ToString();
                        button.OnClientClick = "if (!confirm('Do you want delete this Layout?')) return false;";
                    }
                    if (button != null && button.CommandName == "Save")
                    {
                        // Add delete confirmation
                        //button.CommandArgument = ((TblEmail)e.Row.DataItem).IDEmail.ToString();
                        button.OnClientClick = "if (!confirm('Bạn có muốn lưu không?')) return false;";
                    }
                }
            }
        }
    }

    protected void btnConfirm_Click(object sender, ImageClickEventArgs e)
    {
        bool flag = false;
        try
        {
        }
        catch (Exception ex)
        {
            Session[Global.SESSION_ERROR] = ex;
            Response.Redirect(Global.ERROR_PAGE_ADMIN);
        }
        if (flag)
            Response.Redirect("~/Admin/ListLayout.aspx");
    }
    protected void btnUpdate_Click(object sender, ImageClickEventArgs e)
    {
        int IDLayout = Convert.ToInt32(((ImageButton)sender).CommandArgument);
        Response.Redirect("~/Admin/GetLayoutCode.aspx?idLayout=" + IDLayout);
    }
    protected void grdListlayout_PageIndexChanging(object sender, GridViewPageEventArgs e)
    {
        grdListlayout.PageIndex = e.NewPageIndex;
        LoadListLayout();
    }
}
